<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div id="menuContent" class="menuContent" style="display: none; position: absolute;">
						<ul id="organSelectTree" class="ztree" style="margin-top: 0;width: 200px;"></ul>
					</div>
					<script src="${cxt !}/sb/js/jquery.form.js" type="text/javascript" charset="utf-8"></script>
			<script type="text/javascript">
			var setting = {
				async : {
					enable : true,
					url : '${cxt!}/departmentUser/treeData',
					autoParam : [ "id=ids" ],//, "name=n", "level=lv"
					type : "post"
				},
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					onClick : onClick,
					onAsyncSuccess : organTreeOnAsyncSuccess
				}
			};
			var flag = 0;
			function organTreeOnAsyncSuccess(event, treeId, msg) {
				
				if(flag == 0){
					var organTree = $.fn.zTree.getZTreeObj("organSelectTree");
					var nodes = organTree.getNodes();
					initDeptTable(nodes[0]);
					//initProductStockTable(nodes[0].id);
					flag = 1;
				}
			}
			function onClick(e, treeId, treeNode) {
				initDeptTable(treeNode);
				//initDeptTable(treeNode.id);
				var zTree = $.fn.zTree.getZTreeObj("organSelectTree");
				var path = "";
				var sNodes = zTree.getSelectedNodes();
				if (sNodes.length > 0) {
					var node = sNodes[0].getPath();
					for(var i =0;i<node.length;i++){
						path += node[i].name + "/"
					}
				}
				var cityObj = $("#organ");
				cityObj.attr("value", path);
				$("#organIds").attr("value", treeNode.id);
				
				hideMenu();
				
			}
			function showMenu() {
				
				var cityObj = $("#organ");
				var cityOffset = $("#organ").offset();
				
				$("#menuContent").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
		
				$("body").bind("mousedown", onBodyDown);
				
			}
			function hideMenu() {
				$("#menuContent").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "menuBtn"
						|| event.target.id == "menuContent" || $(event.target)
						.parents("#menuContent").length > 0)) {
					hideMenu();
				}
			}
			$.fn.zTree.init($("#organSelectTree"), setting);
			function initDeptTable(curNode){
				
				$('#deptTable').datagrid({
					cls: "theme-datagrid",			
					toolbar: '#tb',
					singleSelect: false,
					selectOnCheck:$(this).is(':checked'),
					checkOnSelect:$(this).is(':checked'),
					rownumbers: true, //显示序号
					pagination: false,
					//pageSize: 10,
					url: "departmentUser/deptUserList",
					queryParams: {	
						'_query.bh': curNode.bh + "%"
					},
				    method: 'post',
					collapsible: true,
					columns:[[
					          {field:'check',checkbox:true},
						  		{field:'ids',title:'ids',width:100,align:'center', hidden:true},
						  		{field:'username',title:'用户名',width:100,align:'center', hidden:true},
						  		{field:'name',title:'姓名',width:100, align:'center',
						  			
						  		},
						  		{field:'mobile',title:'联系方式',width:160, align:'center'},
						  		{field:'stationname',title:'岗位',width:100, align:'center'},
						  		{field:'dname',title:'部门',width:100, align:'center'},
						  		{field:'status',title:'状态',width:100, align:'center',
						  			formatter: function(value,row,index){
						  				var status = row.status;
						  				if(status == 1){
						  					return '正常';
						  				}else{
						  					return '禁用';
						  				}
						  			}
						  		}
						      ]],
					onLoadSuccess:function(){
						
					}
				});
			}
			//初始化市场负责人下拉框
			/*function initMangerSelect(ids){
				var url = "/common/getUsersByOrgan";
				var param = {
						'ids':ids
					};
				var data = common_ajax.ajaxFunc(url,param,"json");
				/*data.unshift({  
                     'ids': '-1',  
                     'name': '-请选择-'  
                 });
				$('#organMangerIds').combobox({
				    data:data,
				    valueField:'ids',
				    textField:'name',
				    multiple:true,		    
				    onLoadSuccess : function(){  		    	
				    	 var val = $(this).combobox('getData');  
		                   /* for (var item in val[0]) {  
		                        if (item == 'ids') {  
		                            $(this).combobox('select', val[0][item]);  
		                        }  
		                    }
			        }
				});
			}*/
		</script>
</body>
</html> 